package com.tuliyou.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tuliyou.entity.Major;
import com.tuliyou.entity.University;
import com.tuliyou.entity.UserFavorite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface UserFavoriteMapper extends BaseMapper<UserFavorite> {

    @Select("select * from user_favorites where `code` = #{code} and favorite_type = #{favoriteType}")
    UserFavorite getByCodeAndFavorite(String code, String favoriteType);

    @Select("select * from universities where university_code = #{code} and uni_year = 2025 and is_deleted = 0")
    University getUniversity(String code);

    @Select("select * from majors where major_code = #{code} and is_deleted = 0")
    Major getMajor(String code);

    @Update("update user_favorites set is_deleted = 0 and created_at = #{createdAt} where id = #{id}")
    int updateByUfId(Long id, LocalDateTime createdAt);

    @Update("update user_favorites set is_deleted = 1 where id = #{id}")
    int updateByUserFavoriteId(Long id);
}
